package com.zgroup.domain

import com.zgroup.common.WebUtils
import java.util.List

class SysUser {
  final static String COOKIE_USER_NAME = "COOKIE_ADMIN_USER_NAME" // 用户名 Cookie Key
  final static String COOKIE_PASSWORD = "COOKIE_ADMIN_PASSWORD" // 用户密码 Cookie Key

  final static String REQUEST_USER_INFO = "sysUserInfo"

  final static String UPLOAD_FILE_PATH = "/upload/admin/head_picture/"     //发布信息图片上传路径
  final static String UPLOAD_THUMBNAIL_PATH = "/upload/admin/head_thubnail/"     //发布信息缩略图上传路径
  final static String DEFUALT_USER_HEAD = "/images/ui/default_user_head.gif"

  String username     // 用户名 *注：用户注册时，用户名和邮箱一致
  String password     // 密码

  // 个人信息
  String name         // 姓名
  String mobile       // 手机
  String telephone    // 固定电话
  String msn          // MSN
  String qq           // QQ
  String gtalk        // GTALK
  String email        // 邮箱
  String headPicture  // 个人头像
  Date dateCreated
  Date lastUpdated
  Role role


  List getPermission() {
    println("+++++")
    return WebUtils.split(role.permission);
  }


  String getDisplayName() {
    if (name == null) {
      int pos = username.lastIndexOf("@")
      if (pos > -1) {
        return username.substring(0, pos)
      }
      return username
    }
    return name
  }

  String getHeadImage() {
    if (headPicture == null) {
      DEFUALT_USER_HEAD
    } else {
      UPLOAD_FILE_PATH + headPicture
    }
  }

  static transients = ['headImage', 'displayName', 'permission']

  static constraints = {
    username(blank: false, unique: true, maxSize: 50)
    password(blank: false, maxSize: 32)
    name(nullable: true, maxSize: 10)
    mobile(nullable: true, matches: "[0-9]+", maxSize: 30)
    telephone(nullable: true, maxSize: 30)
    msn(nullable: true, email: true, maxSize: 50)
    qq(nullable: true, matches: "[0-9]+", maxSize: 20)
    gtalk(nullable: true, maxSize: 20)
    email(blank: false, email: true, maxSize: 50)
    headPicture(nullable: true, maxSize: 255)


  }
}
